package com.chushouya.controller.manager.admin;

import com.chushouya.common.constant.ServiceType;
import com.chushouya.manager.dto.admin.partner.*;
import com.general.framework.core.enums.BusinessType;
import com.general.framework.core.schema.PageResult;
import com.general.framework.core.schema.Response;
import com.general.framework.web.annotations.Log;
import com.chushouya.manager.service.admin.PartnerPromoteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 渠道与合作商推广
 */
@RestController
@RequestMapping(ServiceType.PLATFORM + "/partnerPromote")
@Api(tags = ServiceType.PLATFORM + "渠道商推广")
public class PartnerPromoteController {

    @Resource
    private PartnerPromoteService partnerPromoteService;

    @GetMapping("/page")
    @ApiOperation("查询列表")
    public Response<PageResult<PartnerPromoteListDTO>> page(PartnerPromoteQuery query) {
        return Response.success(partnerPromoteService.selectPage(query));
    }

    @GetMapping("/detail")
    @ApiOperation("查询详情")
    public Response<PartnerPromoteDetailDTO> detail(Long promoteId) {
        return Response.success(partnerPromoteService.detail(promoteId));
    }

    @PostMapping("/add")
    @ApiOperation("新增")
    @Log(businessType = BusinessType.INSERT)
    public Response<Void> save(@RequestBody @Valid PartnerPromoteSaveDTO dto) {
        partnerPromoteService.save(dto);
        return Response.success();
    }

    @PostMapping("/update")
    @ApiOperation("编辑")
    @Log(businessType = BusinessType.UPDATE)
    public Response<Void> update(@RequestBody @Valid PartnerPromoteUpdateDTO dto) {
        partnerPromoteService.update(dto);
        return Response.success();
    }

    @PostMapping("/switchStatus")
    @ApiOperation("切换状态")
    @Log(businessType = BusinessType.UPDATE)
    public Response<Boolean> switchStatus(Long promoteId) {
        return Response.success(partnerPromoteService.switchStatus(promoteId));
    }

    @PostMapping("/remove")
    @ApiOperation("删除")
    @Log(businessType = BusinessType.DELETE)
    public Response<Void> remove(Long promoteId) {
        partnerPromoteService.remove(promoteId);
        return Response.success();
    }

}
